
###
### JCR Warleader Paper 
###
### Jun Koga Sudduth 
### Descriptive Statistics 
### 

library(foreign)
library(MASS)
library(tidyverse) 
library(haven)



## Data 
dat <- read.table(file="C:/Users/Dell User/Dropbox/Wartimeleader/Data/Leader_Year/wartime_base_89.txt")
dat <- as_tibble(dat)

 
## coups DV 
dat %>% count(insidercoup) 

dat %>% count(noninsidercoup) 


## NOTE on DV: In addition to Powell/Tyne's coup, the data include the following cases as punishment by military and elites following 
## either Archigo's or GWF descriptions.

##35144   640 1997-06-01 TUR-1996-2       13 1997 823da827-1e42-11e4-b4cd-db5882bf8def   TUR            Erbakan     19960628   19970630
##44745   771 2007-01-01   BNG-2006        4 2007 82551e7d-1e42-11e4-b4cd-db5882bf8def   BNG           Iajuddin     20061029   20070112
##46816   790 2002-10-01   NEP-2001       16 2002 19bbd548-3bbd-11e5-afeb-eb6f07f9fec7   NEP  Sher Bahdur Deuba     20010726   20021004

## This is the case where neither Powell/CRS code as coups, though it's consistent with Archigos ( Removed by Military, without Foreign Support  ).
##640  1997   19970630 TUR-1996-2   TUR          Erbakan        <NA>                Removed by Military, without Foreign Support 
## Wiki:He was pressured by the military to step down as prime minister and was later banned from politics by the Constitutional Court 
##of Turkey for violating the separation of religion and state as mandated by the constitution.[1][2]

## BNG-2006: this is coded as success coup by CPS coup dataset and GWF note 

## NEP-2001: 
## King Gyanendra dismissed the PM and ending the the constitutional monarchy (GWF). It does not entail an explicit involvement of militaries (i.e. palace coups).   
## This is consistent with CPS coup coding.





### War-time Data (those leaders who have at least one casualty during the last 12 months or during the war)
 
dat <- dat %>% filter(sum11ps_best_est >=25 | sum12_best_est >=25 |  ongoing25_cyr ==1 | lag1ongoing25_cyr==1 )


dat %>% count(ccode)  # 79 countries 
dat %>% count(obsid)  # 287 eaders 
table(dat$year )  ## 1989 - 2015 


#### Insider v.s. Outsider Coups Descriptive Statistics (Table 1 in the main text)
 
dat %>% count(insidercoup) %>% mutate(freq=n/sum(n))
#insidercoup     n    freq
#<int> <int>   <dbl>
#  1           0 10801 0.998  
#2           1    20 0.00185


dat %>% count(noninsidercoup) %>% mutate(freq=n/sum(n))

#noninsidercoup     n    freq
#<int> <int>   <dbl>
#  1              0 10801 0.998  
#2              1    20 0.00185


dat %>% filter(insidercoup==1) %>% count(regime_gwf_fin) %>% mutate(freq=n/sum(n)) 

#regime_gwf_fin        n  freq
#<fct>             <int> <dbl>
#  1 democracy             8  0.4 
#2 military-personal     1  0.05
#3 party                 2  0.1 
#4 party-military        1  0.05
#5 party-personal        1  0.05
#6 personal              7  0.35


dat %>% filter(noninsidercoup==1) %>% count(regime_gwf_fin) %>% mutate(freq=n/sum(n)) 

#regime_gwf_fin        n  freq
#<fct>             <int> <dbl>
#  1 democracy             8  0.4 
#2 Indirect military     1  0.05
#3 military-personal     3  0.15
#4 party                 2  0.1 
#5 personal              6  0.3 


 






######### 
######## Online Appendix Table (Table 3)
#########

### Making the list of leader entry manner 
class(dat$finarc_entry) 
dat$finarc_entry <- as.character(dat$finarc_entry)

dat <- 
  dat %>% mutate(
    finarc_entry = ifelse(finarc_entry=="First Election/Selection" , "Regular", 
                          ifelse(finarc_entry=="Regular Election/Selection", "Regular", 
                                 ifelse(finarc_entry=="Protest", "Irregular", 
                                        ifelse(finarc_entry=="Successful Rebellion", "Irregular",
                                               ifelse(finarc_entry=="Foreign Installation", "Irregular", 
                                                      ifelse(finarc_entry=="Irregular Election/Selection", "Irregular",
                                                             finarc_entry)))))))
 

#### Nonculpable leader (those who have at least one dyad for which he is not nonculpable)
leadlist <- 
  dat %>% filter(N_nonculp_FinFirstL_Dyad !=0 & !is.na(N_nonculp_FinFirstL_Dyad)  )  %>%  
  filter(N_culp_FinFirstL_Dyad==0  ) %>%    ## this line is different fromn the above
  select(obsid, ccode, idacr, leader_name,  startyrmth, endyrmth, fin_entry, finarc_entry , regular_entry,                        
         regimecoup_entry,  leadercoup_entry,                  
         coup_entry, rebel_entry, protest_entry,  foreign_entry ) %>% distinct

## checking no overlaps        
leadlist %>% count(obsid) %>% filter(n!=1)

## Entry Mannre of Nonculpable Leaders ()

leadlist %>% count(finarc_entry) %>%   ## combination of my ISQ data and Archigo for democracy
  mutate(freq=n/sum(n) ) %>% arrange(n)

#finarc_entry     n   freq
#<chr>        <int>  <dbl>
#  1 Leader Coup      2 0.0138
#2 Regime Coup     11 0.0759
#3 Irregular       29 0.2   
#4 Regular        103 0.710 



### Culpable Leaders 

culp <- 
  dat %>% filter(N_culp_FinFirstL_Dyad!=0 & !is.na(N_culp_FinFirstL_Dyad)  ) %>% 
  filter(N_nonculp_FinFirstL_Dyad==0 ) %>% 
  select(obsid, ccode, idacr, leader_name,  startyrmth, endyrmth, fin_entry, finarc_entry , regular_entry,                        
         regimecoup_entry,  leadercoup_entry,                  
         coup_entry, rebel_entry, protest_entry,  foreign_entry ) %>% distinct

## checking no overlaps        
culp %>% count(obsid) %>% filter(n!=1)

## Entry Mannre of culpable Leaders ()

culp %>% count(finarc_entry) %>%   ## combination of my ISQ data and Archigo for democracy
  mutate(freq=n/sum(n) ) %>% arrange(n)

# finarc_entry     n   freq
#<chr>        <int>  <dbl>
#  1 Leader Coup      2 0.0153
#2 Regime Coup     13 0.0992
#3 Irregular       29 0.221 
#4 Regular         87 0.664 


 




##### 
##### End 
#####

 